package pers.sports.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;
import pers.sports.service.EmailService;

import java.util.Date;

/**
 * 邮件
 *
 * @datetime 2021/3/9 14:02
 */

@Service
public class EmailServiceImpl implements EmailService {

    @Autowired
    JavaMailSender javaMailSender;


    @Override
    public void sendSimpleMail(String to, String Subject, String Text) {
        // 构建一个邮件对象
        SimpleMailMessage message = new SimpleMailMessage();
        // 设置邮件主题
        message.setSubject(Subject);
        // 设置邮件发送者，这个跟application.yml中设置的要一致
        message.setFrom("XXX");
        // 设置邮件接收者，可以有多个接收者，中间用逗号隔开，以下类似
        // message.setTo("10*****16@qq.com","12****32*qq.com");
        message.setTo(to);
        // 设置邮件发送日期
        message.setSentDate(new Date());
        // 设置邮件的正文
        message.setText(Text);
        // 发送邮件
        javaMailSender.send(message);
    }

    @Override
    public void sendHtmlMail(String to, String Subject, String Text) {

    }
}
